#include <fermat/common/class_loader.h>
#include <fermat/common/manifest.h>
#include <fermat/common/cmdline.h>
#include "abstract_plugin.h"
#include <iostream>

typedef fermat::ClassLoader<AbstractPlugin> PluginLoader;
typedef fermat::Manifest<AbstractPlugin> PluginManifest;
int main(int argc, char** argv)
{
    fermat::CmdParser p;
	p.add<std::string>("lib", 'l', "lib path", true, "");
    p.parse_check(argc, argv);
    std::string libpath =  p.get<std::string>("lib");

    PluginLoader loader;
    loader.loadLibrary(libpath);
    PluginLoader::Iterator it(loader.begin());
    PluginLoader::Iterator end(loader.end());
    for (; it != end; ++it)
    {
        std::cout << "lib path: " << it->first << std::endl;
        PluginManifest::Iterator itMan(it->second->begin());
        PluginManifest::Iterator endMan(it->second->end());
        for (; itMan != endMan; ++itMan)
            std::cout << itMan->name() << std::endl;
    }
    AbstractPlugin* pPluginA = loader.create("PluginA");
    AbstractPlugin* pPluginB = loader.create("PluginB");
    std::cout << pPluginA->name() << std::endl;
    std::cout << pPluginB->name() << std::endl;
    //loader.findClass("PluginA")->autoDelete(pPluginA);
    //delete pPluginB;
    loader.unloadLibrary(libpath);
    return 0;
}